package com.ruoyi.business.service.impl;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.business.domain.Laserpowerdetectorhis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.PowderfeederhisMapper;
import com.ruoyi.business.domain.Powderfeederhis;
import com.ruoyi.business.service.IPowderfeederhisService;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author DL
 * @date 2025-07-08
 */
@Service
public class PowderfeederhisServiceImpl implements IPowderfeederhisService 
{
    @Autowired
    private PowderfeederhisMapper powderfeederhisMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param ID 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public Powderfeederhis selectPowderfeederhisByID(Long ID)
    {
        return powderfeederhisMapper.selectPowderfeederhisByID(ID);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param powderfeederhis 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<Powderfeederhis> selectPowderfeederhisList(Powderfeederhis powderfeederhis)
    {
        return powderfeederhisMapper.selectPowderfeederhisList(powderfeederhis);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param powderfeederhis 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertPowderfeederhis(Powderfeederhis powderfeederhis)
    {
        return powderfeederhisMapper.insertPowderfeederhis(powderfeederhis);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param powderfeederhis 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updatePowderfeederhis(Powderfeederhis powderfeederhis)
    {
        return powderfeederhisMapper.updatePowderfeederhis(powderfeederhis);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param IDs 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deletePowderfeederhisByIDs(Long[] IDs)
    {
        return powderfeederhisMapper.deletePowderfeederhisByIDs(IDs);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param ID 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deletePowderfeederhisByID(Long ID)
    {
        return powderfeederhisMapper.deletePowderfeederhisByID(ID);
    }

    @Override
    public Map<String, Object> getPowderfeederhisDataBetween(LocalDateTime startTime, LocalDateTime endTime) {
        // 查询数据库获取数据
        List<Powderfeederhis> dataList = powderfeederhisMapper.findByTimestampBetween(startTime, endTime);

        // 处理数据格式
        Map<String, Object> result = new HashMap<>();
        String[] xdata = new String[dataList.size()];
        double[] DeliveredRealCount1 = new double[dataList.size()];
        double[] DeliveredRealCount2 = new double[dataList.size()];
        double[] IntasurePressure1 = new double[dataList.size()];
        double[] VentingPressure1 = new double[dataList.size()];
        double[] IntasurePressure2 = new double[dataList.size()];
        double[] VentingPressure2 = new double[dataList.size()];
        double[] PowerSetHumi1 = new double[dataList.size()];
        double[] PowerSetHumi2 = new double[dataList.size()];

        // 定义格式化器
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

        for (int i = 0; i < dataList.size(); i++) {
            Powderfeederhis data = dataList.get(i);
            xdata[i] = sdf.format(data.getEventTime());
            DeliveredRealCount1[i] = data.getDeliveredRealCount1() != null ? data.getDeliveredRealCount1().doubleValue() : 0.0;
            DeliveredRealCount2[i] = data.getDeliveredRealCount2() != null ? data.getDeliveredRealCount2().doubleValue() : 0.0;
            IntasurePressure1[i] = data.getIntasurePressure1() != null ? data.getIntasurePressure1().doubleValue() : 0.0;
            VentingPressure1[i] = data.getVentingPressure1() != null ? data.getVentingPressure1().doubleValue() : 0.0;
            IntasurePressure2[i] = data.getIntasurePressure2() != null ? data.getIntasurePressure2().doubleValue() : 0.0;
            VentingPressure2[i] = data.getVentingPressure2() != null ? data.getVentingPressure2().doubleValue() : 0.0;
            PowerSetHumi1[i] = data.getPowerSetHumi1() != null ? data.getPowerSetHumi1().doubleValue() : 0.0;
            PowerSetHumi2[i] = data.getPowerSetHumi2() != null ? data.getPowerSetHumi2().doubleValue() : 0.0;
        }

        result.put("xdata", xdata);
        result.put("DeliveredRealCount1", DeliveredRealCount1);
        result.put("DeliveredRealCount2", DeliveredRealCount2);
        result.put("IntasurePressure1", IntasurePressure1);
        result.put("VentingPressure1", VentingPressure1);
        result.put("IntasurePressure2", IntasurePressure2);
        result.put("VentingPressure2", VentingPressure2);
        result.put("PowerSetHumi1", PowerSetHumi1);
        result.put("PowerSetHumi2", PowerSetHumi2);

        return result;
    }
}
